// Package settings
/*
@Coding : utf-8
@Time : 2023/3/6 0:09
@Author : yizhigopher
@Software : GoLand
*/
package settings

import (
	"ginchat/apis/routers"

	"github.com/gin-contrib/sessions"
	"github.com/gin-contrib/sessions/cookie"
	"github.com/gin-gonic/gin"
	"github.com/spf13/viper"
)

func InitGinEngine() *gin.Engine {
	gin.SetMode(viper.GetString("system.mode"))
	engine := gin.Default()

	store := cookie.NewStore([]byte(viper.GetString("system.Secret")))
	store.Options(sessions.Options{
		MaxAge: viper.GetInt("system.SessionExpireTime"),
	})

	engine.Use(sessions.Sessions("mySession", store))
	routers.InitRouter(engine)
	return engine
}
